package cn.enilu.flash.api.controller.task;

import cn.enilu.flash.api.controller.BaseController;
import cn.enilu.flash.bean.entity.task.TaskStep;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.service.task.TaskStepService;

import cn.enilu.flash.bean.core.BussinessLog;
import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.enumeration.BizExceptionEnum;
import cn.enilu.flash.bean.exception.ApplicationException;
import cn.enilu.flash.bean.vo.front.Ret;
import cn.enilu.flash.bean.vo.front.Rets;

import cn.enilu.flash.utils.factory.Page;


import org.apache.shiro.authz.annotation.RequiresPermissions;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/help/step")
public class TaskStepController extends BaseController {
	private  Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private TaskStepService taskStepService;

	@GetMapping(value = "/list")
	@RequiresPermissions(value = "taskStep")
	public Ret list(@RequestParam(required = false) Long id) {
		Page<TaskStep> page = new PageFactory<TaskStep>().defaultPage();
		page.addFilter("id",id);
		page = taskStepService.queryPage(page);
		return Rets.success(page);
	}
	@GetMapping("/getStepByTaskId")
	public Ret getStepByTaskId(Long taskId){
		List<TaskStep> taskStepList = taskStepService.queryAll(new SearchFilter("taskId", SearchFilter.Operator.EQ, taskId));
		return Rets.success(taskStepList);
	}
	@PostMapping
	@BussinessLog(value = "新增帮助任务步骤", key = "name")
	@RequiresPermissions(value = "taskStepAdd")
	public Ret add(@ModelAttribute TaskStep taskStep){
		taskStepService.insert(taskStep);
		return Rets.success();
	}
	@PutMapping
	@BussinessLog(value = "更新帮助任务步骤", key = "name")
	@RequiresPermissions(value = "taskStepUpdate")
	public Ret update(@ModelAttribute TaskStep taskStep){
		taskStepService.update(taskStep);
		return Rets.success();
	}
	@DeleteMapping
	@BussinessLog(value = "删除帮助任务步骤", key = "id")
	@RequiresPermissions(value = "taskStepDelete")
	public Ret remove(Long id){
		if (id == null) {
			throw new ApplicationException(BizExceptionEnum.REQUEST_NULL);
		}
		taskStepService.delete(id);
		return Rets.success();
	}
	@GetMapping("/getTaskSteps")
	public Ret getList(Long taskId){
		List<TaskStep> taskId1 = taskStepService.queryAll(new SearchFilter("taskId", SearchFilter.Operator.EQ, taskId));
		return Rets.success(taskId1);
	}
}